home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************************
- **
- ** I have tried to name all my functions in the following fashion: example_name,
- ** yet_another_example, etc.
- **
- ** I did this to make sure that other folks who come in and read my code will be
- ** able to quickly discern betwen my functions and Toolbox calls just by looking
- ** at the naming convention.
- **
- ** My constants and globals are prepended by a k and g, respectively.
- */
-
- #ifndef __THREADUTIL__
- #include <ThreadUtil.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- /***********************************************************************************
- **
- ** Constants.
- */
-
- #define TRUE 1
- #define FALSE 0
-
- /* Philo stuff */
- #define kNumOfPhilosophizers 5
- #define kIconDimension 32
- #define kIconOffset 15
- #define kNumAllowedIn kNumOfPhilosophizers - 1
- #define kNumberOfIterations 2000
- #define kThinkingTimeLimit 10
- #define kEatingTimeLimit 10
-
- /* Fork state */
- #define kNoForks 0
- #define kLeftFork 1
- #define kBothForks 2
-
- /* Icon IDs */
- #define kNoForkIcon 150
- #define kLeftForkIcon 200
- #define kBothForksIcon 250
-
- /* Menu IDs */
- #define kAppleMenu 128
- #define kFileMenu 129
-
- /* Item IDs */
- #define kAboutItem 1
- #define kQuitItem 1
-
- /* WNE parameter */
- #define kSleepTicks 60
-
- /* Error flags */
- #define kFatal 1
- #define kNotFatal 0
-
- /* Alert dialog stuff */
- #define kAboutThisApp 200
- #define kErrorAlert 129
-
- #define kPictID 128
-
-
- /***********************************************************************************
- **
- ** Structs
- */
-
- typedef struct { /* Resource handles, where it is, does it have a fork */
- Rect thinking_location, waiting_location, dining_location;
- Rect current_location;
- short left_fork, fork_state;
- ThreadID theThread;
- } philoRecord, *philoPtr;
-
-
- /***********************************************************************************
- **
- ** Function Prototypes
- */
-
- /*
- ** main.c
- */
- /* App utils */
- void system_attrib(void);
- void error(Str255, short, short);
- void cpy_pas_string(Str63 *, Str63);
- short is_DA_window(WindowPtr);
-
- /* Init stuff */
- void init_mac(void);
- WindowPtr init_rooms(void);
- void init_philosophizers(WindowPtr);
- void init_threads(void);
-
- /* Menus, events */
- void menu_command(long);
- void do_apple_menu(short);
- void event_loop(void);
- void keydown_evt(EventRecord);
- void mousedown_evt(EventRecord);
- void update_evt(EventRecord);
- void suspend_resume_evt(EventRecord);
-
- /* Drawing */
- void draw_background(WindowPtr);
- void draw_philosophizers(WindowPtr);
- void draw_and_slam(WindowPtr);
-
-
-
- /*
- ** threadstuff.c
- */
- /* Thread execution */
- void spawn_threads(void);
- pascal void *philo_actions(void *);
- void think_for_a_while();
- void go_to_eat(philoPtr);
- void eat_for_a_while(philoPtr);
- void go_to_think(philoPtr);
-
- /* Forks */
- void create_forks(void);
- void pick_up_right_fork(philoPtr);
- void pick_up_left_fork(philoPtr);
- void put_down_right_fork(philoPtr);
- void put_down_left_fork(philoPtr);
- void remove_forks(void);
-
- /* Footman */
- void create_footman(void);
- void checkin_with_footman(void);
- void checkout_with_footman(void);
- void retire_footman(void);